package com.kyle.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kyle.dao.MenuDao;
import com.kyle.dao.RoleDao;
import com.kyle.entity.DeptEntity;
import com.kyle.entity.Menu;
import com.kyle.entity.RoleEntity;
import com.kyle.entity.util.JsonResult;
import com.kyle.entity.util.PageBean;

@Controller
@SuppressWarnings({"rawtypes","unchecked"})
@RequestMapping("/role")
public class RoleAction {

	@Autowired
	@Qualifier(value="roleDao")
	private RoleDao roleDao;
	
	@RequestMapping(value="/getRoleList.xhtml")
	@ResponseBody
	public JsonResult getRoleList(PageBean pageBean,
			HttpServletRequest request,HttpServletResponse response){
		JsonResult jsonResult = new JsonResult();
		
		List<RoleEntity> roleList = roleDao.getScrollData(pageBean, null, null, null);
		Object rows = roleDao.getScrollDataCount(null, null);
		jsonResult.setTotal(rows);
		jsonResult.setRows(roleList);
		return jsonResult;
	}
	
	@RequestMapping(value="/addRole.xhtml")
	@ResponseBody
	public JsonResult addRole(RoleEntity roleEntity,HttpServletRequest request,HttpServletResponse response){
		JsonResult jsonResult = new JsonResult();
		try {
			roleDao.saveEntity(roleEntity);
			jsonResult.setMsg("添加成功");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			jsonResult.setState(false);
			jsonResult.setMsg("添加失败");
		}		
		return jsonResult;
	}
}
